<?php if ($session->read('Auth.User.prefix') == CUST_PREFIX) : ?>
    <?php echo $this->element('displayHeader'); ?>
<?php endif; ?>
<div class="toolbar"><?php echo $this->element('toolbar', array('buttons' => array(array('refresh' => array('action' => 'stock_out_cost_center_search'))))); ?></div>

<?php echo $form->create(null, array('action' => 'stock_out_cost_center', 'target' => '_blank')); ?>
<fieldset>
    <legend>Criteria</legend>
    <table>
        <tr>
            <td width="120"><?php echo $form->label('SiteCostCenter.id', 'Cost Center'); ?></td>
            <td width="500px" colspan="3">
            <?php echo $form->select('SiteCostCenter.id', $costCenters, null, null, OPTION_ALL ); ?>
            </td>
        </tr>
        <tr>
            <td colspan="4"><hr /></td>
        </tr>
        <tr>
            <td class="top"><?php echo $form->label('CustStockOutHead.stock_out_date', 'Stock out Date'); ?></td>
            <td colspan="3">
                From <?php echo $form->text('CustStockOutHead.stock_out_date_start', array('size' => 7, 'class' => 'text-right')); ?>
                To <?php echo $form->text('CustStockOutHead.stock_out_date_end', array('size' => 7, 'class' => 'text-right')); ?>
            </td>
        </tr>
        <tr>
            <td colspan="4"><hr /></td>
        </tr>
    </table>
    <table>
        <tr>
            <td class="top" width="150px"><?php echo $form->label('display', 'Additional Information'); ?></td>
            <td>
                <?php echo $form->checkbox('Option.display_stock_out_no'); ?>&nbsp;&nbsp;Stock out no. / Stock out date/ Remark / Product Description
            </td>
        </tr>
    </table>
    <?php echo $this->element('report/buttons', array('action' => 'stock_out', 'button' => array('search', 'print', 'excel'))); ?>
</fieldset>
<?php echo $form->end(); ?>

<script type="text/javascript">
    $j(function() {
        $j.datesearchpicker("#CustStockOutHeadStockOutDate");
        $j(':radio[id^=CustStockOutHeadDispatchFrom]').bind('click', function() {
            var dispatch_from = $j(this).val();
            if (dispatch_from == SUPPLIER_PREFIX) {
                $j('#CustStockOutHeadSupplierId').show();
                // ถ้าเลือก ITS หรือ All
            } else {
                $j('#CustStockOutHeadSupplierId').hide().val('');
                // Request option ของ ITS กลับมาใส่ใหม่
                $j('#ProductBrandId').requestOptions('cust_product_sites/option_its_brand_list', null, {empty_option: '--All--'});
            }
        });

        // ติ๊ก dispatch from all ไว้ก่อน
        $j('#CustStockOutHeadDispatchFrom').attr('checked', true);
        $j('button').handover();

        $j('#CustStockOutHeadSupplierId').bind('change', function() {
            $j('#ProductBrandId').requestOptions('brands/option_list', $j(this).val(), {empty_option: '--All--'});
        });

        $j(':input').bind('keypress', stopKeyEnter);
    });
</script>


<?php echo $this->element('report/result'); ?>
